# 遍历数据，查询数据出现的位置
from elasticsearch import Elasticsearch

# 连接到Elasticsearch实例
es = Elasticsearch(['http://192.168.0.1:9200'])  # 请根据您的实际情况修改Elasticsearch实例的URL

# 定义要查询的索引名称
index_name = "&haikou.air_vocs_hour_stats"

# 执行初始查询，设置scroll参数
result = es.search(index=index_name, body={"size": 1000}, scroll='1m')

# 提取第13131条数据
scroll_id = result['_scroll_id']
scroll_size = result['hits']['total']['value']
count = 0

while scroll_size > 0:
    for hit in result['hits']['hits']:
        count += 1
        if hit['_source']['id'] == '2022-09-01 02:00:001102A':
            print("第{}条数据：".format(count), hit['_source'])
        # if count == 13131:
        #     print("第13131条数据：", hit['_source'])
        #     break

    result = es.scroll(scroll_id=scroll_id, scroll='1m')
    scroll_id = result['_scroll_id']
    scroll_size = len(result['hits']['hits'])

